package com.shujia.wyh.day20;

import java.util.TreeSet;

/*
        TreeSet存储自定义对象并遍历并按照年龄从大到小进行排序
 */
public class TreeSetDemo2 {
    public static void main(String[] args) {
        //创建TreeSet集合对象
        TreeSet<Student3> set = new TreeSet<>();

        //创建学生对象
        Student3 s1 = new Student3("小白", 18);
        Student3 s2 = new Student3("红红", 17);
        Student3 s3 = new Student3("嘿嘿", 16);
        Student3 s4 = new Student3("小白", 18);
        Student3 s5 = new Student3("小白", 20);

        //将学生对象添加到集合中
        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        set.add(s5);

        //遍历集合
        for (Student3 student3 : set) {
            System.out.println(student3);
        }
    }
}
